<template>
	<div>
		 <div class="status_bar"> 
		    <div class="top_div"></div>
		</div>
		<div class="content">
			<div class="searchbox">
				<input type="text" class="s_input" placeholder="搜索" v-model="searchtxt" return-key-type="search" @blur="search" />
			</div>			
			<scroller class="prolist" scroll-direction="vertical" @loadmore="loadMoreData" loadmoreoffset="30"> 
				<proitem :item="itm" v-for="(itm,inx) in list" :key="inx" @goInfo="goInfo(itm)" @follow="follow(itm)"></proitem>
				<div v-if="list.length==0" class="nomoredata"><text class="nomoredtxt">无更多数据</text></div>
			</scroller>
		</div>
	</div>
</template>

<script>
	import proitem from "@/components/pro-item.nvue";
	export default {
		components:{
			proitem
		},
		data(){
			return {
				searchtxt:"",//搜索文字
				curCity:0,
				curPage:1,
				sys:{},
				list:[]
			}
		},
		updated(){console.log("update")},
		mounted(){console.log("mounted")},
		created(){
			var _this = this;
			uni.getStorage({ key:"$system" ,success(res) {
				_this.sys = res.data;
			}});
			uni.getStorage({
				"key":"storage_key",
				success(e){
					_this.userInfo = e.data;
					if(!_this.userInfo.uid){
						uni.showToast({
							icon:"none",
							title:"未登录！"
						})
						uni.navigateTo({
							url: '/pages/public/login/login'
						});
						return;
					}
					_this.getData();
					if(_this.userInfo.ispass){
						uni.showToast({
							title: '账号已被查封，请与管理员联系',
							icon:"none" 
						});
						uni.navigateTo({
							url: '/pages/public/login/login'
						});
					}
				}
			})
		},
		methods:{
			goInfo(itm){
				uni.navigateTo({
					url:"/pages/home/proInfo?id="+itm.id+"&token="+itm.access_token+"&uid="+itm.uid
				})
			},
			loadMoreData(){
				this.curPage++;				
				this.getData();
			},
			follow(itm,inx){
				let url = "";
				let _this = this;
				if(itm.isFollow==0){ url = "http://apptest.pinchao.cc/api.php/Store/follow"; }
				else{ url = "http://apptest.pinchao.cc/api.php/Store/delFollow"; }
				console.log(url)
				uni.request({
					url:url,
					method:"post",
					header:{
						app_version:'1.0.0',
						system_version:_this.system,
						"Content-Type":"application/x-www-form-urlencoded"
					},
					data:{
						"store_id":itm.id,
						"access_token":_this.userInfo.access_token,
						"uid":_this.userInfo.uid
					},
					responseType:"arraybuffer",
					success(res) {
						//console.log(res)
						if(res.data.ret == '200'){
							if(itm.isFollow==0) itm.isFollow =1;
							else itm.isFollow =0;
							_this.list.splice(inx,1)
							uni.showToast({
								title:"操作成功"
							})
						}else{
							uni.showToast({
								icon:"none",
								title:res.data.msg
							})
						}
							
					},
					error(err){
						console.log("err:",err)
					}
				})
			},
			search(e){
				this.list = [];
				this.getData("follow",this.cityId);
				console.log(this.searchtxt)
			},
			getData(str="follow",cityId="0"){
				var _this = this;
				uni.request({
					url:"http://apptest.pinchao.cc/api.php/Store/getList",
					method:"post",
					header:{
						app_version:'1.0.0',
						system_version:_this.system,
						"Content-Type":"application/x-www-form-urlencoded"
					},
					data:{
						"access_token":_this.userInfo.access_token,
						"uid":_this.userInfo.uid,
						"keyword":this.searchtxt,
						"type":"follow",
						"page":this.curPage
					},
					
					responseType:"arraybuffer",
					success(res) {
						
						if(res.data.ret == '200'){
							if(res.data.data[0].id){
								_this.list =_this.list.concat( res.data.data); 
							}
							
						}else{
							uni.showToast({
								icon:"none",
								title:res.data.msg
							})
						}
							
					},
					error(err){
						console.log("err:",err)
					},
					complete() {
						_this.loadinging = false;
					}
				})
			}
		}
	}
</script>

<style>
	
	.nomoredata{
		width: 130upx;
		height: 60upx;
		margin-top: 40upx;
		
	}
	.nomoredtxt{
		text-align: center;
		color: #A0A0A0;
	}
	.prolist{
		width: 750upx;
		height: 1200upx;
		flex-direction: column;
		align-items: center;
	}
.status_bar{
		width: 750upx;
		height: 44upx;
		background-color: #000;
	}
.searchbox{
	width: 750upx;
	height: 84upx;
	background-color: #000;
}
.s_input{
	width: 702;
	height: 60upx;
	margin: 12upx 24upx;
	background-color: #fff;
	text-align: center;
}
.scroller{
	width: 750upx;
	height: 74upx;
	border-bottom-width: 1upx;
	border-bottom-style: solid;
	border-bottom-color: #E6E6E6;
	flex-direction: row;
}
.scrollItem{
	width: 80upx;
	height: 74upx;
	margin: 0 20upx;
	text-align: center;
	line-height: 74upx;
	display: inline-block;
	font-size: 32upx;
}
.curItem{
	border-bottom-width: 4upx;
	border-bottom-color: #DBC600;
}
</style>
